package com.bsoft.gol.editor.controller;


import hcn.util.BaseResponse;
import com.bsoft.gol.editor.editor.EditorCommonWidget;
import com.bsoft.gol.editor.editor.EditorWidgetClass;
import com.bsoft.gol.editor.editor.request.WidgetCommonReq;
import com.bsoft.gol.editor.editor.response.EditorCommonWidgetRes;
import com.bsoft.gol.editor.editor.response.EditorQuestionnaireTitleRes;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import com.bsoft.gol.editor.service.EditorCommonWidgetApi;

import java.util.List;

/**
 *
 * @author lxy
 * @date 2019/6/18
 */
@Controller
@RequestMapping(value = "/api/auth/editorCommonWidget")
public class EditorCommonWidgetController {

    @Autowired
    private EditorCommonWidgetApi editorCommonWidgetApi;

    @RequestMapping("/add")
    @ResponseBody
    @Deprecated
    public BaseResponse<EditorCommonWidgetRes> add(@RequestBody WidgetCommonReq req) {
        BaseResponse<EditorCommonWidgetRes> response = new BaseResponse<>();
        EditorCommonWidget editorCommonWidget = new EditorCommonWidget();
        editorCommonWidget.setWidgetClassId(req.getClassId());
        editorCommonWidget.setCommonWidgetDesc(req.getWidgetDesc());
        editorCommonWidget.setCommonWidgetName(req.getWidgetName());
        editorCommonWidget.setCommonWidgetType(req.getWidgetType());
        EditorCommonWidgetRes res = editorCommonWidgetApi.add(editorCommonWidget, req.getTitleName());
        response.setData(res);
        return response;
    }

    @RequestMapping("/detail")
    @ResponseBody
    public BaseResponse<EditorQuestionnaireTitleRes> detail(@RequestBody WidgetCommonReq req) {
        BaseResponse<EditorQuestionnaireTitleRes> response = new BaseResponse<>();
        EditorQuestionnaireTitleRes res = editorCommonWidgetApi.detail(req.getWidgetId());
        response.setData(res);
        return response;
    }

    @RequestMapping("/list")
    @ResponseBody
    public BaseResponse<List<EditorCommonWidgetRes>> list(@RequestBody WidgetCommonReq req) {
        BaseResponse<List<EditorCommonWidgetRes>> response = new BaseResponse<>();
        List<EditorCommonWidgetRes> list = editorCommonWidgetApi.list(req.getClassId());
        response.setData(list);
        return response;
    }

    @RequestMapping("/delete")
    @ResponseBody
    public BaseResponse<List<EditorWidgetClass>> delete(@RequestBody WidgetCommonReq req) {
        BaseResponse<List<EditorWidgetClass>> response = new BaseResponse<>();
        editorCommonWidgetApi.delete(req.getWidgetId());
        return response;
    }

}
